<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>MyGallery</title>
				
		<script src="http://leoner.tianji.com/dojo/dojo.js" djConfig="parseOnLoad:true, isDebug:true"></script>
		<script type="text/javascript">
			dojo.require("dojo.io.script");
			dojo.require("doh.runner");
			dojo.addOnLoad(function(){
				var _requestCount = 0 ;
				var callbackFn = "";
				var _createContent = function(callback){
					console.log("1-->"+callback);
					return {
						callback:callback
					};
				};		
				var deferred;
				var getData = function(){
					console.log(callbackFn);
					console.log(deferred);
				
					if(deferred){
						deferred.cancel();
						deferred = null;
						dojo.global[callbackFn] =function(){};
					}
				
					callbackFn = ("fn"+(++_requestCount));
					var getArgs = {
						url: "http://leoner.tianji.com/jersey/jsonp/jsonp/5",
						content:_createContent(callbackFn),
						handle:function(){
							console.log("*************");
						}
					};
					
					deferred = dojo.io.script.get(getArgs);
					deferred.addErrback(function(error){
						console.log(error);
					});
					dojo.global[callbackFn] = function(start, data, responseCode, errorMsg){
						
						console.log("------------------");
						var callback1 = callbackFn;
						console.log("callbackFn-->"+callback1);
						console.log(start);
						console.log(data);
						console.log(responseCode);
						console.log(errorMsg);
						console.log("------------------");
					}
				}
				var getData1 = function(){
					dojo.io.script.get({
						callbackParamName : "callback", //provided by the jsonp service
						url: "http://leoner.tianji.com/jersey/jsonp/jsonp/error",
						load : function(response, ioArgs) {
							alert("aa");
							console.log(response);
							return response;
						},
						error:function(response, ioArgs) {
							alert("ss");
							return response;
						}
					});
				}
				
				dojo.connect(dojo.byId("test"),"onclick",null,getData);
			});
		</script>
	</head>
	<body>
		<div id="output"></div>
		<input type="button" id="test" value="get data" />
	</body>
</html>
